package com.Ajava1704.for设计模式.for单例模式;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @类名: com.Ajava1704.for设计模式.for单例模式
 * @作者: lgt
 * @创建时间: 2020-02-15 16:45
 * @描述:
 **/
public class ForTest009 {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        CountDownLatch countDownLatch = new CountDownLatch(4);
        MyCallable myCallable = new MyCallable(countDownLatch);

        FutureTask f1 = new FutureTask(myCallable);
        Thread t1 = new Thread(f1);
        t1.start();

        FutureTask f2 = new FutureTask(myCallable);
        Thread t2 = new Thread(f2);
        t2.start();

        FutureTask f3 = new FutureTask(myCallable);
        Thread t3 = new Thread(f3);
        t3.start();

        FutureTask f4 = new FutureTask(myCallable);
        Thread t4 = new Thread(f4);
        t4.start();

        countDownLatch.await();
        Object o1 = f1.get();
        Object o2 = f2.get();
        Object o3 = f3.get();
        Object o4 = f4.get();
        System.out.println(o1==o2);
        System.out.println(o1==o3);
        System.out.println(o1==o4);


    }
}
